<?php
namespace app\yangxt_forum_admin\controller;
use think\Controller;
class Bindeal extends Controller
{
    // 帖子放入回收站
    public function binMesDel()
    {   
        $re = db('mes')
            ->where('mid',input('mid'))
            ->setField(['checkdel'=>1,'mdelat'=>time(),'because'=>'帖子放入回收站']);

           if ($re) {
            $reg =db('res')
            ->where('mid',input('mid'))
            ->setField(['checkdel'=>1,'rdelat'=>time(),'because'=>'帖子放入回收站']);
            if($reg){
                $this -> success('加入回收站成功,并且该帖子的回复也加入回收站',url("deal/mesdeal",['mid'=>input('mid'),'sid'=>input('sid')]));
            }
           	
           }
    }

// 帖子回收站显示
     public function binmesdeal($sid=0)
    {   
        $sel=db('section')
        ->select();

        if ($sid==0) {
            $sousuo=input('check');
                $backmes =db('mes')
                ->where('mtitle','like','%'.$sousuo.'%')
                ->select();
                $sename='结果';
        }

        foreach ($sel as $key => $value) {
            if ($value['sid']==input('sid')) {

                $sename=$value['sname'];
                break;
            };
        }

        $how=input('back');
        if ($how==2 and $sid!=0) {
        	$backmes=db('mes')
        	->where('checkdel',1)
        	->where('sid',input('sid'))
        	->select();
        }
        elseif ($how==2 and $sid==0){
        	$backmes=db('mes')
        	->where('checkdel',1)
        	->where('mtitle','like','%'.input('check').'%')
        	->select();
       	 	$sename='搜索';
        };
        $hind=db('section')
       ->where('sid',input('sid'))
       ->select();
        $hides='';
        foreach ($hind as $key => &$value) {
            if ($value['checkdel']==1) {

                $hides='none';
            }
            else{
                $hides='';
            }
        }
        return view("",['sel'=>$sel,'sname'=>$sename,'backdata'=>$backmes,'hides'=>$hides]);
    }
// 板块回收站显示
    public function binsecdeal($sid=0)
    {   
        $sel=db('section')
        ->select();

        if ($sid==0) {
            $sousuo=input('check');
                $backmes=db('section')
                ->where('sname','like','%'.$sousuo.'%')
               
                ->select();
                $sename='结果';
        }

        $how=input('back');
        if ($how==1 and $sid!=0) {
            $backmes=db('section')
           
            ->select();
        }
        elseif ($how==1 and $sid==0){
            $backmes=db('section')
           
            ->where('sname','like','%'.input('check').'%')
            ->select();
        };

        return view("",['sel'=>$sel,'backdata'=>$backmes]);
    }

// 回复回收站显示
    public function binresdeal($sid=0)
    {   
        $sel=db('section')
        ->select();

        if ($sid==0) {
            $sousuo=input('check');
                $check=db('res')
                ->where('rcontent','like','%'.$sousuo.'%')
                ->select();
                $sename='结果';
        }

        foreach ($sel as $key => $value) {
            if ($value['sid']==input('sid')) {

                $sename=$value['sname'];
                break;
            };
        $check = db()
            ->view('mes','mtitle')
            ->view("res","rcontent,rcreateat,unick,rdelat,because,mid,rid","mes.mid=res.mid")
            ->where('sid',input('sid'))
            ->where('res.checkdel',1)
            ->select();


        }
        $how=input('back');
        if ($how==3 and $sid!=0) {
            $check = db()
            ->view('mes','mtitle,checkdel')
            ->view("res","rcontent,rcreateat,unick,rdelat,because,mid,rid","mes.mid=res.mid")
            ->where('sid',input('sid'))
            ->where('res.checkdel',1)
            ->select();
        }
        elseif ($how==3 and $sid==0){
            $check = db()
            ->view('mes','mtitle,checkdel')
            ->view("res","rcontent,rcreateat,unick,rdelat,because,mid,rid","mes.mid=res.mid")
            ->where('rcontent','like','%'.input('check').'%')
            ->where('res.checkdel',1)
            ->select();
            $sename='搜索';
        };
        foreach ($check as $key => &$value) {
            if ($value['checkdel']==1) {

                $value['hides']='none';
            }
            else{
                $value['hides']='';
            }
        }
        
        return view("",['sel'=>$sel,'sname'=>$sename,'check'=>$check]);
    }
    // 回收站帖子还原
  public function binmeset()
    {   
    	$how=input('back');
    	if ($how==2) {
    		$re = db('mes')
            ->where('mid',input('mid'))
            ->setField(['checkdel'=>0,'mdelat'=>0,'because'=>'']);
    	}
    	if ($re) {
           	$this -> success('还原成功',url("bindeal/binmesdeal",['sid'=>1,'back'=>2]));
           }
           else{
           	$this -> error('还原失败',url("bindeal/binmesdeal",['sid'=>1,'back'=>2]));
           }
        
    }
    // 回收站板块还原
     public function binsecet()
    {   
        $how=input('back');
        if ($how==1) {
            $re = db('section')
            ->where('sid',input('sid'))
            ->setField(['checkdel'=>0,'sdelat'=>0,'because'=>'']);
        }
        if ($re) {
            $this -> success('还原成功',url("bindeal/binsecdeal",['sid'=>1,'back'=>1]));
           }
           else{
            $this -> error('还原失败',url("bindeal/binsecdeal",['sid'=>1,'back'=>1]));
           }
        
    }
// 回复还原
public function binreset()
    {   
        $how=input('back');
        if ($how==3) {
            $re = db('res')
            ->where('rid',input('rid'))
            ->setField(['checkdel'=>0,'rdelat'=>0,'because'=>'']);
        }
        if ($re) {
            $this -> success('还原成功',url("bindeal/binresdeal",['sid'=>1,'back'=>3]));
           }
           else{
            $this -> error('还原失败',url("bindeal/binresdeal",['sid'=>1,'back'=>3]));
           }
        
    }

// 将板块放入回收站
    public function binsecdel()
    {   
        $sec = db('section')
            ->where('sid',input('sid'))
            ->setField(['checkdel'=>1,'sdelat'=>time(),'because'=>'板块放入回收站']);

           if ($sec) {
            $mec = db()
            ->view('mes','checkdel,mdelat,because,mid')
            ->view('res','checkdel,mdelat,because,mid','mes.mid=res.mid')
            ->where('mes.sid',input('sid'))
            ->setField(['mes.checkdel'=>1,'mdelat'=>time(),'mes.because'=>'板块放入回收站','res.checkdel'=>1,'rdelat'=>time(),'res.because'=>'板块放入回收站']);

            $this -> success('加入回收站成功',"deal/secdeal");
           }
        
    }
// 将回复放入回收站
public function binresdel()
    {   
        $sec = db('res')
            ->where('rid',input('rid'))
            ->setField(['checkdel'=>1,'rdelat'=>time(),'because'=>'回复放入回收站']);

           if ($sec) {
            $this -> success('加入回收站成功',url("deal/adetail",['mid'=>input('mid')]));
           }
        
    }
}
 